package com.heer.gymnasium.base;

import com.orangegangsters.github.swipyrefreshlayout.library.SwipyRefreshLayout;
import com.orangegangsters.github.swipyrefreshlayout.library.SwipyRefreshLayoutDirection;

/**
 * Created by rzw2 on 2017/4/5.
 */

public class BaseRefreshActivity extends BaseActivity implements SwipyRefreshLayout.OnRefreshListener {
    protected SwipyRefreshLayout layoutRefresh;
    protected int pageNo = 1;
    protected int REFRESH_RES_ID;

    @Override
    protected void initView() {
        super.initView();
        if (REFRESH_RES_ID > 0) {
            layoutRefresh = (SwipyRefreshLayout) findViewById(REFRESH_RES_ID);
            layoutRefresh.setOnRefreshListener(this);
        }
    }


    public void setRefreshResId(int resId) {
        this.REFRESH_RES_ID = resId;
    }

    @Override
    public void onRefresh(SwipyRefreshLayoutDirection direction) {
        if (direction == SwipyRefreshLayoutDirection.TOP) {
            pageNo = 1;
            loadData(false);
        } else if (direction == SwipyRefreshLayoutDirection.BOTTOM) {
            pageNo++;
            loadData(true);
        }
    }


}
